#include <bits/stdc++.h>
using namespace std;
struct car{
    int d,v,a;
    int s,t;
};
bool operator <(const car lhs,const car rhs){
    return lhs.t<rhs.t;
}
void solve(int n,int m,int L,int V){
    vector<car>cars;
    for(int i=0;i<n;i++){
        car c;
        cin>>c.d>>c.v>>c.a;
        if(c.v<=V&&c.a<=0)continue;
        if(c.v>V){
            c.s=c.d;
            if(c.a>=0)c.t=L;
            else{
                long double t=(long double)(V-c.v)/c.a;
                c.t=(int)floor(c.v*t+0.5*c.a*t*t)+c.d;
            }
        }
        else{
            long double t=(long double)(V-c.v)/c.a;
            c.s=(int)floor(c.v*t+0.5*c.a*t*t)+1+c.d;
            if(c.s>L)continue;
            c.t=L;
        }
        cars.push_back(c);
    }
    n=cars.size();
    sort(cars.begin(),cars.end());
    vector<int>p(m);
    for(int i=0;i<m;i++)cin>>p[i];
    int i=0,j=0;
    int ans1=0,ans2=0,pj=-1;
    for(;i<n&&j<m;){
        while(i<n&&cars[i].s<=pj)ans1++,i++;
        if(i>=n)break;
        while(j<m&&p[j]<=cars[i].t)j++;
        if(j>0)j--;
        if(p[j]<cars[i].s||p[j]>cars[i].t){
            i++;
            continue;
        }
        ans2++;pj=p[j];
        while(i<n&&cars[i].s<=p[j])ans1++,i++;
    }
    cout<<ans1<<' '<<m-ans2<<endl;
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        solve(n,m,L,V);
    }
    return 0;
}